package cn.cdiothree.controller;


import cn.cdiothree.service.ProductCartService;
import cn.cdiothree.service.ProductCategoryService;
import cn.cdiothree.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author CumThing
 * @since 2020-02-02
 */
@RestController
@RequestMapping("/product-cart")
public class ProductCartController {

    @Autowired
    ProductCartService productCartService;

    /**
     * 添加商品到购物车
     * @param userId
     * @param productId
     * @param count
     * @return
     */
    @PostMapping("/addOrDecrease")
    public ResultVO addOrDecrease(@RequestParam("userId") Integer userId,
                        @RequestParam("productId") Integer productId, Integer count){
        ResultVO productCart = productCartService.addOrDecrease(userId,productId,count);
        return ResultVO.success(productCart);
    }

    /**
     * 减少购物车商品
     * @param userId
     * @param productId
     * @param count
     * @return
     */
//    @PostMapping("/decrease")
//    public ResultVO decrease(@RequestParam("userId") Integer userId,
//                             @RequestParam("productId") Integer productId,Integer count){
//        ResultVO productCart = productCartService.decrease(userId,productId,count);
//        return ResultVO.success(productCart);
//    }

    /**
     * 删除购物车商品
     * @param userId
     * @param productId
     * @return
     */
    @GetMapping("/delete")
    public ResultVO deleteByUserIdAndProductId(@RequestParam("userId") Integer userId,
                                               @RequestParam("productId") Integer productId){
        ResultVO productCart = productCartService.deleteByUserIdAndProductId(userId,productId);
        return ResultVO.success(productCart);
    }

}
